
local outcomelist1="VANTAGE_V3_SCORE  COL5060 ANY_AUT_OR_LEASE  zerorevolving ALL5042 fin_health"

use unique_id `outcomelist1'  qsince evicted monthsince archive_year using "${build}/exp_analysis.dta"  if monthsince>=-48 & monthsince<=72, clear

***********************************
*      Event Study Quarterly      *
***********************************
qui tab qsince, gen(qdum)
foreach num of numlist 1(1)41 {
		gen evictXq`num'=evicted*qdum`num'
}

local controls="i.archive_year"
fvset base 2011 archive_year

*Quarter variable
gen q_plot=.
foreach num of numlist 1(1)41 {
		local plotpos=`num'
		local rel_q=`num'-17
		replace q_plot=`rel_q'    in `plotpos'
}
replace q_plot=999 in 42
replace q_plot=9999 in 43

label var zerorevolving "No Open Revolving Account"
label var fin_health "Financial Health"

local vnum=1
foreach var of varlist `outcomelist1' {
	gen var`vnum'_q_est=.
	gen var`vnum'_qXevict_est=.
	gen var`vnum'_q_se=.
	gen var`vnum'_qXevict_se=.
	gen str var`vnum'_name=`"`:variable label `var''"' in 1/43
	
	noi disp "`var'"
	
	reg `var' evicted qdum1-qdum4 qdum6-qdum41 evictXq1-evictXq4 evictXq6-evictXq41 `controls'
	sum `var' if evicted==0 & qdum5==1
	replace var`vnum'_q_est=r(mean) if q_plot==999
	replace var`vnum'_q_est=_b[evicted] if q_plot==9999
	
	foreach num of numlist 1(1)4 6(1)41 {
		local plotpos=`num'
		local rel_q=`num'-17
		replace var`vnum'_q_est=_b[qdum`num'] in `plotpos'
		replace var`vnum'_qXevict_est=_b[evictXq`num'] in `plotpos'
		replace var`vnum'_q_se=_se[qdum`num'] in `plotpos'
		replace var`vnum'_qXevict_se=_se[evictXq`num'] in `plotpos'
	}
	local vnum=`vnum'+1
}
preserve
keep q_plot var*
keep if _n<=43
tostring q_plot, replace
replace q_plot="Non-evict mean t=-12" if q_plot=="999"
replace q_plot="Evict coefficient" if q_plot=="9999"
export delimited using "${Inputs}/Cook_experian_eventstudy.csv", replace